package com.xiaoha.pogy.controllers;


import com.xiaoha.pogy.dao.BookRepository;
import com.xiaoha.pogy.dao.BorrowRepository;
import com.xiaoha.pogy.dao.StudentRepository;
import com.xiaoha.pogy.dto.BookBorrow;
import com.xiaoha.pogy.entities.Book;
import com.xiaoha.pogy.entities.Borrow;
import com.xiaoha.pogy.entities.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class HomeController {

    @Autowired
    BookRepository bookRepository;

    @Autowired
    BorrowRepository borrowRepository;



    @GetMapping("/")
    public String displayHome(Model model){

        List<Book> books = bookRepository.findAll();
        model.addAttribute("books",books);

       List<Borrow> borrows = borrowRepository.findAll();
       model.addAttribute("borrows",borrows);

        List<BookBorrow> bookBorrows = bookRepository.bookBorrows();
        model.addAttribute("bookBorrows",bookBorrows);


        return "main/home";
    }


}
